package com.superlistaportable.resultList;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;

import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;


public class ResultListController {
	private final ResultListView view;
	private final ResultListModel model;
	private final ResultListActivity activity;
	
	public ResultListController(ResultListModel model, ResultListView view, ResultListActivity activity) {
		this.view = view;
		this.model = model;
		this.activity = activity;
		ArrayList<String> resultList = model.getResultList();
		if(resultList.isEmpty()){
			view.getListResult().setAdapter(new ArrayAdapter<String>(activity, android.R.layout.simple_list_item_1, Arrays.asList("No se seleccionó ningún producto")));
			view.ocultarBotonesYTexto();
		} else {
			view.setTotal();
			view.getListResult().setAdapter(new ArrayAdapter<String>(activity, android.R.layout.simple_list_item_1, resultList));
		}
	}
	
	public void setListeners() {

		view.getButtonCalendario().setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				
				Intent intent = new Intent(Intent.ACTION_EDIT);  
				intent.setType("vnd.android.cursor.item/event");
				intent.putExtra("title", "Tu compra de Hoy");
				intent.putExtra("description", model.getListaItems());
				intent.putExtra("beginTime", Calendar.getInstance().getTimeInMillis());
				intent.putExtra("endTime", Calendar.getInstance().getTimeInMillis());
				activity.startActivity(intent);

		
			}
			
		});
	}
}
